<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>审图模块页面-审图页面</title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta http-equiv="Expires" CONTENT="0">
    <meta http-equiv="Cache-Control" content="no-siteapp,no-transform,no-store, no-cache, must-revalidate">
    <meta http-equiv="Pragma" content="no-cache">
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="/static/css/font.css">
    <link rel="stylesheet" href="/lib/layui/css/layui.css">
    <link rel="stylesheet" href="/static/css/weadmin.css">
    <script type="text/javascript" src="/lib/layui/layui.js" charset="utf-8"></script>
    <link rel="stylesheet" href="/static/css/buildUnit/common.css">
    <script type="text/javascript" src="/lib/mxDraw/mxcustom.js"></script>
    <style>
        body {
            padding: 0;
            -webkit-box-sizing: border-box;
            -moz-box-sizing: border-box;
            box-sizing: border-box;
        }

        .drawingObj {
            height: 100%;
            width: 100%;
        }
    </style>
</head>
<body>
<!--<div class="layui-btn-group" id="drawingBtnView" style="height:38px;">
    <script type="text/html" id="drawingBtn">
        &lt;!&ndash;{{# if(d.permission==true){ }}&ndash;&gt;
        {{# if(d.edit){ }}
        <button class="layui-btn" data-type="addSuggest">添加意见</button>
        <button class="layui-btn" data-type="circleSuggest">圈阅意见</button>
        {{# } }}
        <button class="layui-btn" data-type="speciatySuggest">本专业意见</button>
        {{# if(d.edit){ }}
        <button class="layui-btn" data-type="addConclusion">添加结论</button>
        <button class="layui-btn" data-type="suggestBase">意见库</button>
        <button class="layui-btn" data-type="dwgContrast">图纸对比</button>
        {{# } }}
        {{# } }}
    </script>
</div>-->
<div id="toolbar"
     style="float:left;height:40px;position:relative;left:0;top:0;width:100%;height:auto;border-bottom:solid 2px #000000" class="layui-btn-group drawingBtn hide" >
    <script type="text/html" id="drawingBtn">
        <button class="layui-btn" data-type="ScaleUp">放大</button>
        <button class="layui-btn" data-type="ScaleDown">缩小</button>
        <button class="layui-btn" data-type="RotateLeft">左旋转</button>
        <button class="layui-btn" data-type="RotateRight">右旋转</button>
        <!--<button class="layui-btn" data-type="GoToPrevPage">上一页</button>
        <button class="layui-btn" data-type="GoToNextPage">下一页</button>-->
        <button class="layui-btn" data-type="Print">打印</button>
        <button class="layui-btn" data-type="DoStamp">签章</button>
        <button class="layui-btn" data-type="DoMarkup">圈阅</button>
        <button class="layui-btn" data-type="MeasureDistance">测距</button>
        <button class="layui-btn" data-type="MeasureAngle">测角度</button>
        <button class="layui-btn" data-type="MeasurePerimeter">测周长</button>
        <button class="layui-btn" data-type="MeasureArea">测面积</button>
        <button class="layui-btn" data-type="addSuggest">添加意见</button>
        <button class="layui-btn" data-type="circleSuggest">圈阅意见</button>
        <button class="layui-btn" data-type="speciatySuggest">本专业意见</button>
        <button class="layui-btn" data-type="addConclusion">添加结论</button>
        <button class="layui-btn" data-type="suggestBase">意见库</button>
        <button class="layui-btn" data-type="dwgContrast">图纸对比</button>

    </script>
</div>
<div id="content">

</div>
<script src="../../../static/js/main.js"></script>
<!-- pdf批注完成事件 -->
<script language="javascript" for=iStylePDF event="OnAnnotFinished(Annot, wParam, lParam)">
    layui.use(['pdf'], function () {
        var pdf = layui.pdf;
        pdf.suggestAdd(Annot, wParam, lParam);
    });
</script>
<!-- pdf双击圈阅修改事件 -->
<script language="javascript" for=iStylePDF event="OnAddinEventInvoke(EventName, Addin, wParam, lParam)">
    if (EventName == "iStylePDF.Annots:LButtonDblClk") {
        layui.use(['pdf'], function () {
            var pdf = layui.pdf;
            pdf.suggestEdit(EventName, Addin, wParam, lParam);
        });
        Addin.MsgHandle = true;
    }
</script>
<script>
    //例子图纸：http://61.55.140.248:8094/ysb_store_path/drawing/6e6fbe961ac84e768f8e2c76fe65520d/761364b59d4a4804b695d9d95103ea83/b084bdeed5854c1ba80ecd5e1113bb2f.dwg
    layui.use(['layer', 'mxDraw', 'configure', 'jquery', 'suggest', 'allHeight', 'sessionFun', 'matchType', 'bluebird', 'pdf', 'pdfXiaoling', 'configureCom', 'templateInit'], function () {
        var configure = layui.configure;
        var $ = layui.jquery;
        var mxDraw = layui.mxDraw;
        var suggest = layui.suggest;
        var allHeight = layui.allHeight;
        var sessionFun = layui.sessionFun;
        var matchType = layui.matchType;
        var pdf = layui.pdf;
        var pdfXiaoling = layui.pdfXiaoling;
        var configureCom = layui.configureCom;
        var templateInit = layui.templateInit;
        //获取当前审查对象
        var listData = sessionFun.get(configure.SESSION_PROJECT_WAIT_LIST_DATA);
        //获取图纸对象
        var drawingData = sessionFun.get(configure.SESSION_DRAWING_DATA);
        //通过图纸名称，获得图纸类型
        var drawingType = matchType.init(drawingData.name);
        //获取文件id
        var fileId = matchType.init(drawingData.id);
        //demo图纸
        var url = configure.HOST + configure.DRAWING_WATCH + '?decId=' + listData.decId + '&filePath=' + encodeURIComponent(drawingData.path) + '&token=' + configureCom.getToken();
        if(drawingData.canEdit == true){
            $('.drawingBtn').show();
            allHeight.init1('.drawingBtn', '#content');
        }
        if(drawingData.canEdit == false){
            $('.drawingBtn').hide();
            allHeight.init2('.drawingBtn', '#content');
        }
        if (drawingType === 'pdf') {
            //pdf初始化
            //pdf.init('iStylePDF', url, '#content');//梦想圈阅插件
            pdfXiaoling.init('iStylePDF',fileId, url, '#content');
        } else {
            //cad图纸初始化
            mxDraw.init('drawingId', url, 'http://www.mxdraw.com/MxDrawX52.CAB#version=8.0.0.1', '#content');
        }
        templateInit.init('toolbar', {
            edit: true,
            ifCircle: !(drawingType === 'pdf')
        }, $('#drawingBtn').html());
        //高度计算
        //菜单栏监听按钮点击事件
        $('#toolbar').on('click', 'button', function () {
            var btnType = $(this).attr('data-type');
            switch (btnType) {
                case 'ScaleUp': // 放大
                    ScaleUp();
                    break;
                case 'ScaleDown': // 缩小
                    ScaleDown();
                    break;
                case 'RotateLeft': // 左旋转
                    RotateLeft();
                    break;
                case 'RotateRight': // 右旋转
                    RotateRight();
                    break;
                case 'GoToPrevPage': // 上一页
                    GoToPrevPage();
                    break;
                case 'GoToNextPage': // 下一页
                    GoToNextPage();
                    break;
                case 'Print': // 打印
                    Print();
                    break;
                case 'DoStamp': // 签章
                    DoStamp();
                    break;
                case 'DoMarkup': // 圈阅
                    DoMarkup();
                    break;
                case 'MeasureDistance': // 测距
                    MeasureDistance();
                    break;
                case 'MeasureAngle': // 测角度
                    MeasureAngle();
                    break;
                case 'MeasurePerimeter': // 测周长
                    MeasurePerimeter();
                    break;
                case 'MeasureArea': // 测面积
                    MeasureArea();
                    break;
                case 'addSuggest': // 添加意见
                    addSuggest();
                    break;
                case 'circleSuggest': // 圈阅意见
                    circleSuggest();
                    break;
                case 'speciatySuggest': // 专业意见
                    speciatySuggest();
                    break;
                case 'addConclusion': // 添加结论
                    addConclusion();
                    break;
                case 'suggestBase': //意见库
                    suggestBase();
                    break;
                case 'dwgContrast'://图纸对比
                    dwgContrast();
                    break;
            }
        });
        var obj = document.getElementById("iStylePDF");
        //放大
        function ScaleUp() {
            obj.ScaleUp();
        }

        //缩小
        function ScaleDown() {
            obj.ScaleDown();
        }

        //坐旋转
        function RotateLeft() {
            obj.RotateLeft();
        }

        //右旋转
        function RotateRight() {
            obj.RotateRight();
        }

        //上一页
        function GoToPrevPage() {
            var iCurPageNo = obj.GetCurrentPageNumber();
            var nTotalPages = obj.GetPageCount();
            iCurPageNo--;
            if (iCurPageNo <= 0)
                return;
            document.getElementById("pageno_input").value = iCurPageNo;
            obj.GoToPage(iCurPageNo);
        }

        //下一页
        function GoToNextPage() {
            var iCurPageNo = obj.GetCurrentPageNumber();
            var nTotalPages = obj.GetPageCount();
            iCurPageNo++;
            if (iCurPageNo >= nTotalPages)
                iCurPageNo = nTotalPages;
            document.getElementById("pageno_input").value = iCurPageNo;
            obj.GoToPage(iCurPageNo);
        }

        //跳转第几页
        function PageNumberChanded() {
            var pageNo = document.getElementById("pageno_input").value;
            obj.GoToPage(pageNo);
        }

        //打印
        function Print() {
            obj.PrintDocument();
        }

        //签章
        function DoMarkup() {
            obj.DoMarkup();
        }

        //圈阅
        function DoStamp() {
            var btn_logout = document.getElementById("logout");
            obj.DoStamp();
            var isLogin = obj.Islogin();
            if (isLogin == 1) {
                btn_logout.disabled = false;
            }
        }
        //测距
        function MeasureDistance(){
            obj.MeasureDistance();
        }
        //测角度
        function MeasureAngle(){
            obj.MeasureAngle();
        }
        //测周长
        function MeasurePerimeter(){
            obj.MeasurePerimeter();
        }
        //测面积
        function MeasureArea(){
            obj.MeasureArea();
        }


        //添加意见
        function addSuggest() {
            sessionFun.remove(configure.SESSION_SUGGEST_DATA);
            top.layer.open({
                type: 2,
                title: '添加意见',
                area: configureCom.Psize1,
                content: configure.EXPERT_ADD_SUGGEST_HTML,
                btnAlign: 'c',
                btn: ['保存'],
                yes: function (index, layero) {
                    var iframeWin = top.window.frames['layui-layer-iframe' + index]; //得到iframe页的窗口对
                    iframeWin.getData().then(function (res) {
                        suggest.add(res.result).then(function () {
                            top.layer.msg('保存成功');
                            top.layer.close(index);
                        });
                    });
                }
            });
        }

        //圈阅意见
        function circleSuggest() {
            if (drawingType === 'pdf') {
                pdfCircle();
            } else {
                cadCircle();
            }
        }

        function cadCircle() {//dwg圈阅意见
            sessionFun.remove(configure.SESSION_SUGGEST_DATA);
            mxDraw.DoCmd(1);
        }

        function pdfCircle() {//pdf圈阅意见
            sessionFun.remove(configure.SESSION_SUGGEST_DATA);
            pdfXiaoling.circle();
        }

        window.update = function () {
            if (drawingType === 'pdf') {
                //pdf圈阅更新
            } else {
                //dwg圈阅更新
                mxDraw.updateAllComment();
            }
        };

        window.deleteYj = function (id) {
            if (drawingType === 'pdf') {
                //pdf圈阅更新
                pdf.removeCircle(id);
            } else {
                //dwg圈阅更新
                mxDraw.updateAllComment();
            }
        };

        //本专业意见列表
        function speciatySuggest() {
            top.layer.open({
                type: 2,
                title: '本专业意见',
                area: configureCom.Psize1,
                content: configure.EXPERT_SPECIATY_SUGGEST_HTML
            });
        }

        //添加结论
        function addConclusion() {
            var title = '添加结论';
            top.layer.open({
                type: 2,
                title: '添加结论',
                area: configureCom.Psize1,
                content: configure.SPEC_RESULT_LIST_HTML,
                btnAlign: 'c',
                btn: ['保存'],
                yes: function (index, layero) {
                    var iframeWin = top.window.frames['layui-layer-iframe' + index]; //得到iframe页的窗口对
                    iframeWin.getData().then(function (res) {
                        var data = {
                            decId: listData.decId,
                            specialtyId: drawingData.specialtyId,
                            roleResults: res.result
                        };
                        configureCom.postDataAjax(configure.EXPERT_SPEC_RESULT_UPDATE_HTTP, data).then(function (data) {
                            if (data.code == 0) {
                                top.layer.msg('保存成功！');
                                top.layer.close(index);
                            }
                        });
                    });
                }
            });
        }

        //意见库
        function suggestBase() {
            var url = configure.EXPERT_SUGGEST_BASE_HTML + '?drawingType=' + drawingType;
            var title = '意见库';
            configureCom.klmyPop([url, title], false, false, function (layero, index) {
                window.circleApply = function () {//圈阅引用
                    mxDraw.DoCmd(1);
                    top.layer.close(index);
                }
            });
        }

        //图纸对比
        function dwgContrast() {
            parent.choseDwgContrast();
        }
    });

</script>
<SCRIPT language="javascript" type="text/javascript" FOR="iStylePDF" EVENT="EventCreateMarkup(fileid, markupID)">
    //圈阅
    layui.use(['pdfXiaoling','configureCom','configure','suggest','sessionFun','matchType'], function () {
        var pdfXiaoling = layui.pdfXiaoling;
        var configureCom = layui.configureCom;
        var configure = layui.configure;
        var suggest = layui.suggest;
        var sessionFun = layui.sessionFun;
        var matchType = layui.matchType;
        //获取图纸对象
        var drawingData = sessionFun.get(configure.SESSION_DRAWING_DATA);
        top.layer.open({
            type: 2,
            title: '圈阅意见',
            area: configureCom.Psize1,
            content: configureCom.nocache(configure.EXPERT_ADD_SUGGEST_HTML),
            btnAlign: 'c',
            btn: ['保存', '取消'],
            yes: function (index, layero) {
                var iframeWin = top.window.frames['layui-layer-iframe' + index];
                iframeWin.getData().then(function (res) {
                    var data = res.result;
                    suggest.add(data).then(function (res) {
                        top.layer.alert('添加成功！');
                        var obj = document.getElementById("iStylePDF");
                        var FileID = matchType.init(drawingData.id);
                        var MarkupInfo = obj.GetMarkupInfo();
                        obj.SetMarkupInfo(FileID,MarkupInfo);

                        console.log(FileID);
                        console.log(MarkupInfo);
                        console.log(obj.SetMarkupInfo(FileID,MarkupInfo));
                    });
                    top.layer.close(index);
                });
            }
        });
    });
</SCRIPT>
<SCRIPT language="javascript" type="text/javascript" FOR="iStylePDF" EVENT="EventDoubleClickMarkup(fileid, markupID)">
    //点击圈阅区域
    layui.use(['pdfXiaoling','configureCom','configure','suggest'], function () {
        var pdfXiaoling = layui.pdfXiaoling;
        var configureCom = layui.configureCom;
        var configure = layui.configure;
        var suggest = layui.suggest;
        var sessionFun = layui.sessionFun;
        var matchType = layui.matchType;
        //获取图纸对象
        var drawingData = sessionFun.get(configure.SESSION_DRAWING_DATA);

        var obj = document.getElementById("iStylePDF");
        var FileID = matchType.init(drawingData.id);
        var MarkupInfo = obj.GetMarkupInfo();
        obj.SetMarkupInfo(FileID,MarkupInfo);
        console.log(obj.SetMarkupInfo(FileID,MarkupInfo));
        /*top.layer.open({
            type: 2,
            title: '圈阅意见',
            area: configureCom.Psize1,
            content: configureCom.nocache(configure.EXPERT_ADD_SUGGEST_HTML),
            btnAlign: 'c',
            btn: ['保存', '取消'],
            yes: function (index, layero) {
                var iframeWin = top.window.frames['layui-layer-iframe' + index];
                iframeWin.getData().then(function (res) {
                    var data = res.result;
                    suggest.add(data).then(function (res) {
                        top.layer.alert('添加成功！');
                        var obj = document.getElementById("iStylePDF");
                        var FileID = matchType.init(drawingData.id);
                        var MarkupInfo = obj.GetMarkupInfo();
                        obj.SetMarkupInfo(FileID,MarkupInfo);
                    });
                    top.layer.close(index);
                });
            }
        });*/
    });
</SCRIPT>

<SCRIPT language="javascript" type="text/javascript" FOR="iStylePDF" EVENT="EventDeleteMarkup(fileid, markupID)">
    // 去服务端数据库删除圈阅信息
    // 另外还需要调用ocx的GetMarkupInfo()获取当前文档所有的圈阅信息更新至服务端
</SCRIPT>
</body>
</html>